//
//  test_url.h
//  TestMac
//
//  Created by 小星星吃KFC on 2021/6/4.
//

#import <Foundation/Foundation.h>


static void test_url(void){
    
    /**
     
     URLFragmentAllowedCharacterSet  "#%<>[\]^`{|}
     URLHostAllowedCharacterSet      "#%/<>?@\^`{|}
     URLPasswordAllowedCharacterSet  "#%/:<>?@[\]^`{|}
     URLPathAllowedCharacterSet      "#%;<>?[\]^`{|}
     URLQueryAllowedCharacterSet     "#%<>[\]^`{|}
     URLUserAllowedCharacterSet      "#%/:<>?@[\]^`
     
     
     */
    NSLog(@"UTF8String == %s", @"中文".UTF8String);
    
    
    NSLog(@"NSUTF8StringEncoding == %@", [NSString stringWithCString:@"中文".UTF8String encoding:NSUTF8StringEncoding]);
    
    //        NSLog(@"NSURL = %@",[NSURL URLWithString:@"http://weapp.igw.com/index.html?_bids=SGCCINTSBZSTP#/"]);
    
    
    NSString *url1 = @"http://weapp.igw.com/index.html?_bids=SGCCINTSBZSTP#/";
    
    NSString *str2= [url1 stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    //        [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSLog(@"str2 = %@",str2);
    
    
    {
        
        NSString *url= [url1 stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
        
        
        //            NSString *url = str2;
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        //传入url创建url组件类
        NSURLComponents *urlComponents = [NSURLComponents componentsWithString:url];
        NSLog(@"urlComponents.UR = %@",urlComponents.URL);
        //回调遍历所有参数，添加入字典
        [urlComponents.queryItems enumerateObjectsUsingBlock:^(NSURLQueryItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            dict[obj.name] = obj.value;
        }];
        NSLog(@"dict = %@",dict);
        
    }
}
